public subroutine FileRename(file, file2)
rename a file. If renamed file already exists it is not overwritten
and warning is raised.
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
character(len=*),
|
intent(in) |
|
|
:: |
file |
|
character(len=*),
|
intent(in) |
|
|
:: |
file2 |
|
Variables
Type |
Visibility | Attributes |
|
Name |
| Initial | |
character(len=100),
|
public |
|
:: |
cmd |
|
|
|
Source Code
SUBROUTINE FileRename &
!
(file,file2)
IMPLICIT NONE
!Arguments with intent(in):
CHARACTER (LEN = *), INTENT(IN) :: file
CHARACTER (LEN = *), INTENT(IN) :: file2
! Local declarations:
CHARACTER (LEN = 100) :: cmd
!------------end of declaration------------------------------------------------
IF (FileExists (file2)) THEN
CALL Catch ('warning', 'FileSys', &
'trying to rename an existing file: ', &
argument = file2 )
RETURN
END IF
IF (GetOS () == WIN32) THEN !detected Windows OS
cmd = 'rename ' // file // ' ' // file2
CALL System (cmd)
ELSE !detected unix like OS, including linux
cmd = 'mv ' // file // ' ' // file2
CALL System (cmd)
END IF
END SUBROUTINE FileRename